export async function onRequest(context) {
  try {
    // 获取原始请求
    const request = context.request;
    // 构造目标 URL：将原始请求路径和查询参数拼接到 https://www.aa.com
    const url = new URL(request.url);
    const path=url.pathname.substring(url.pathname.lastIndexOf("/"));
    const targetUrl = `http://yps.aotbot.com:5230/memos.api.v1.AuthService${path}${url.search}`;
    console.log("targetUrl "+targetUrl)
    // 构建新的请求
    const newRequest = new Request(targetUrl, {
      method: request.method,
      headers: request.headers,
      body: request.body,
    });

    // 发送请求到 aa.com
    const response = await fetch(newRequest);
    return response;
  } catch (error) {
    // 错误处理
    console.error("Proxy error:", error);
    return new Response("Failed to proxy request to aa.com: " + error.message, { status: 500 });
  }
}